package org.itboys.mobile.controller.web;

import com.wordnik.swagger.annotations.Api;
import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mobile.entity.mongo.SundayApply;
import org.itboys.mobile.entity.mongo.SundayComment;
import org.itboys.mobile.service.mongo.web.SundayCommentService;
import org.itboys.mobile.util.ResponseMessage;
import org.itboys.param.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author：贾琦磊
 * @Date：2018/7/17
 * @Description：web端评论审核接口
 *
 */
@Controller
@RequestMapping("/sunday/web/comment")
public class SundayCommentController extends BaseController{

    @Autowired
    private SundayCommentService commentService;

    @RequestMapping("/index")
    public String index(HttpServletResponse response, HttpServletRequest request){
        return "sunday/comment/index";
    }

    @RequestMapping("/select")
    public void select(HttpServletRequest request, HttpServletResponse response
    ,@RequestParam("status")Integer status){
        try {
            PageResult<SundayComment> result = commentService.select(request,status);
            JsonPageUtils.renderJsonPage(result.getTotal(),result.getData(),response);
        } catch (Exception e) {
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE, CommonConstants.FAIL));
        }
    }

    @RequestMapping("/setStatus")
    public void setStatus(HttpServletRequest request, HttpServletResponse response
    , @RequestParam("id")Long id
    ,@RequestParam("status")Integer status){
        try {
            commentService.setStatus(id,status);
            ResponseMessage.success();
        } catch (Exception e) {
            e.printStackTrace();
            ResponseMessage.error(CommonConstants.FAIL_CODE,"error");
        }
    }
}
